package org.example.common.response;

public class ResponseData {
    private String code;
    private String msg;
    private Object data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    //成功分为有数据和无数据传输
    public static  ResponseData success(){//无数据类型返回无数据的ResponseData
        return success(null);
    }
    public static ResponseData success(Object data){//有数据类型返回有数据类型的ResponseData
       ResponseData responseData =new ResponseData();
       responseData.setCode(ResponseEnum.SUCCESS.getCode());
       responseData.setMsg(ResponseEnum.SUCCESS.getMsg());
       responseData.setData(data);
       return responseData;
    }
    public static ResponseData error(ResponseEnum responseEnum){//错误只需要返回错误的号码和信息
    ResponseData responseData=new ResponseData();
    responseData.setCode(responseEnum.getCode());
    responseData.setMsg(responseEnum.getMsg());
    return responseData;//返回一个ResponseData对象
    }
}
